using System;
using System.Collections;
using System.Collections.Generic;

namespace GeoAPI.DataStructures.Collections.Generic
{
    /// <summary>
    /// Simple Wrapper for wrapping an regular Enumerator as a generic Enumberator&lt;T&gt;
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <exception cref="InvalidCastException">
    /// If the wrapped has any item that is not of Type T, InvalidCastException could be thrown at any time
    /// </exception>
    public struct EnumeratorWrapper<T> : IEnumerator<T>
    {
        private IEnumerator innerEnumerator;

        public EnumeratorWrapper(IEnumerator toWrap)
        {
            innerEnumerator = toWrap;
        }

        #region IEnumerator<T> Members

        public T Current
        {
            get { return (T) innerEnumerator.Current; }
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            innerEnumerator = null;
        }

        #endregion

        #region IEnumerator Members

        object IEnumerator.Current
        {
            get { return innerEnumerator.Current; }
        }

        public Boolean MoveNext()
        {
            return innerEnumerator.MoveNext();
        }

        public void Reset()
        {
            innerEnumerator.Reset();
        }

        #endregion
    }
}